package com.qf.xiaomi.web.listeners;

import com.qf.xiaomi.pojo.TbGoodsType;
import com.qf.xiaomi.service.goodsTypeService;
import com.qf.xiaomi.service.impl.goodsTypeServiceImpl;
import com.sun.deploy.net.HttpDownloadListener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionListener;
import java.util.List;
@WebListener
public class MyContextLoadListener implements ServletContextListener {
           goodsTypeService service= new goodsTypeServiceImpl();
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //服务器加载监听器  从中查询数据库
        List<TbGoodsType> goodsTypes = service.selectType();
        servletContextEvent.getServletContext().setAttribute("goodsTypeList",goodsTypes);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    servletContextEvent.getServletContext().removeAttribute("goodsTypeList");
    }
}
